package com.itheima.controller.user;


import com.itheima.common.entity.Result;
import com.itheima.pojo.MemberTOD;
import com.itheima.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/member")
public class MemberController {

    @Autowired
    RedisTemplate redisTemplate;
    @Autowired
    private MemberService memberService;
    @PostMapping("/login")
    public Result login(@RequestBody MemberTOD memberTOD) {

        String code = memberTOD.getValidateCode();
        String code2 = (String) redisTemplate.opsForValue().get(memberTOD.getTelephone());
        if(!code2.contains(code)){
            return new Result(false, "验证码错误");
        }

        memberService.register(memberTOD);


        redisTemplate.delete(memberTOD.getTelephone());
        return new Result(true, "登陆成功", "用户信息获取成功");
    }

}
